package org.datascooter.impl;

import java.sql.SQLException;

import org.datascooter.cache.ConnectionBundle;
import org.datascooter.utils.policy.SnipType;

class SnipSelfExecutor extends SimpleExecutor {

	public SnipSelfExecutor(boolean supportPagination, boolean callParameterMetadata, ConnectionBundle bundleIn) {
		super(supportPagination, callParameterMetadata);
		bundle = bundleIn;
	}

	@Override
	public void execute(Snip snip) throws SQLException {
		try {
			if (snip.type.equals(SnipType.SELECT) || snip.type.equals(SnipType.GROUP)) {
				retrieve(null, snip);
			} else if (snip.type.equals(SnipType.FUNCTION)) {
				executeCount(snip);
			} else {
				executeSimple(null, snip);
			}
		} catch (SQLException e) {
			rollback();
			throw e;
		}
		commit();
	}
}
